{extend name="public:layout" /}
{block name="title"}维修保养完成{/block}
{block name="head"}{/block}
{block name="body"}
<div class="wrapper wrapper-content">
    <div class="ibox">
        <div class="ibox-content">
            <form method="post" class="form-horizontal" id="form" action="{:url('logic.query/infoRecord')}">
                <input class="form-control" type="hidden" name="aid" value="{$info.aid}" datatype="*" />
                <input class="form-control" type="hidden" name="mid" value="15" datatype="*" />
                <input class="form-control" type="hidden" name="is_update" value="1" datatype="*" />
                <input class="form-control" type="hidden" placeholder="维修处理人" name="repair_uid" value="{$uid}" datatype="*" />
                <input class="form-control" type="hidden" name="ser_end_time" value="{php}echo time();{/php}" datatype="*" />
                <div class="form-group">
                    <label class="col-sm-2 control-label Validform_label">车牌号</label>
                    <div class="col-sm-3">
                        <input class="form-control" type="text" name="car_sn" value="{$info.car_sn}" datatype="*" readonly/>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label Validform_label">问题说明</label>
                    <div class="col-sm-8">
                        <input class="form-control" type="text" placeholder="" name="title" value="{$info.title}" datatype="*"  />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label Validform_label">维修费用</label>
                    <div class="col-sm-4">
                        <input class="form-control" type="text" placeholder="" name="service_money" value="{$info['service_money']}"  />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label Validform_label">轮胎编码(左前)</label>
                    <div class="col-sm-3">
                        <input class="form-control" name="shoe1" value="{:get_field_value('car','shoe1',['aid'=>$info.car_id])}"/>
                    </div>
                    <label class="col-sm-2 control-label Validform_label">轮胎编码(右前)</label>
                    <div class="col-sm-3">
                        <input class="form-control" name="shoe2" value="{:get_field_value('car','shoe2',['aid'=>$info.car_id])}"/>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label Validform_label">轮胎编码(左后)</label>
                    <div class="col-sm-3">
                        <input class="form-control" name="shoe3" value="{:get_field_value('car','shoe3',['aid'=>$info.car_id])}"/>
                    </div>
                    <label class="col-sm-2 control-label Validform_label">轮胎编码(右后)</label>
                    <div class="col-sm-3">
                        <input class="form-control" name="shoe4" value="{:get_field_value('car','shoe4',['aid'=>$info.car_id])}"/>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label Validform_label">选择配件</label>
                    <div class="col-sm-8">
                        <input type="text" name="parts" id="select-client" placeholder="请输入配件名称检索" data-init="" style="width:100%;" />
                        <script>
                            In('selectpage',function(){
                                $('#select-client').selectPage({
                                    keyField:'aid',
                                    showField:'title',
                                    multiple:true,
                                    pagination:true,
                                    dbTable:'car_parts',
                                    data:'/plus/ajax/selectpage',
                                    andOr:'OR',
                                    params : function(){return {'searchField':'parts_code'}},
                                    eAjaxSuccess : function(data){
                                        if(data.totalRow>0){
                                            return data;
                                        }else{
                                            return false;
                                        }
                                    },
                                    eSelect:function (data) {

                                    },
                                    formatItem : function(data){
                                        return data.parts_name+'['+data.parts_model+']';
                                    }
                                });
                            })
                        </script>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label Validform_label">配件使用</label>
                    <div class="col-sm-8" id="parts-box">

                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label Validform_label">备注信息</label>
                    <div class="col-sm-8">
                        <textarea class="form-control" rows="3" name="ser_remarks" >{$info['ser_remarks']}</textarea>
                    </div>
                </div>
                <div class="form-group" style="display:none;">
                    <label class="col-sm-2 control-label Validform_label">维修状态</label>
                    <div class="col-sm-4">
                        <label class="radio-inline i-checks"><input type='radio' name="service_status" value="0" /> 已提交</label>
                        <label class="radio-inline i-checks"><input type='radio' name="service_status" value="1" /> 开始处理</label>
                        <label class="radio-inline i-checks"><input type='radio' name="service_status" value="2" checked/> 处理完成</label>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-10 col-sm-offset-2">
                        <button class="btn btn-primary" id="btnSub" type="button">保存</button>
                        <a href="javascript:;" onclick="layer.closeAll()" class="btn btn-white">取消</a>
                        <span id="validError"></span>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script type="text/html" id="parts-tpl">
    <table class="table table-condensed">
        <tr>
            <th width="240">配件名称</th>
            <th>配件型号</th>
            <th>单价</th>
            <th width="80">数量</th>
        </tr>
        {{ each data as value index }}
        <tr>
            <td><input type="text" name="ser_desc[{{ index }}][parts_name]" class="form-control" value="{{ value.parts_name }}" datatype="*" /></td>
            <td><input type="text" name="ser_desc[{{ index }}][parts_model]" class="form-control" value="{{ value.parts_model }}" datatype="*" /></td>
            <td><input type="text" name="ser_desc[{{ index }}][parts_price]" class="form-control" value="{{ value.parts_price }}" datatype="*" /></td>
            <td><input type="text" name="ser_desc[{{ index }}][parts_num]" class="form-control" value="" datatype="*" /></td>
        </tr>
        {{ /each }}
    </table>
</script>
<script type="text/javascript">
    $(function () {
        iCheck();
        formatDate();
    });
    In('validform','layer',function(){
        $("#form").Validform({
            btnSubmit:'#btnSub',
            ajaxPost: true,
            postonce: true,
            tipSweep: true,
            callback: function (res) {
                if(res.code==1){
                    var car_data={
                        aid:"{$info.car_id}",
                        mid:5,
                        shoe1:$('input[name="shoe1"]').val(),
                        shoe2:$('input[name="shoe2"]').val(),
                        shoe3:$('input[name="shoe3"]').val(),
                        shoe4:$('input[name="shoe4"]').val(),
                        is_update:1,
                        car_status:0,
                    }
                    $.post("{:url('logic.query/upcar')}",car_data,function (res) {
                        if(res.code==1){
                            layer.msg('维修工单已处理',{time:1000},function () {
                                top.layer.closeAll();
                                refresh();
                            })
                        }else{
                            layer.msg(res.msg);
                        }
                    })
                }else{
                    layer.msg(res.msg);
                }
            }
        });
    })
    $('input[name="parts"]').change(function () {
       var value=$('input[name="parts"]').val();
       $.post("{:url('logic.query/getList')}",{mid:8,aid:value},function (res) {
           console.log(res);
           In('templete','layer',function () {
               var html=template('parts-tpl',{data:res});
               $('#parts-box').empty().html(html);
           })
       })
    })

</script>
{/block}